package com.mall.order.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.db.Db;
import com.mall.order.rocketmq.Consumer;
import com.mall.order.rocketmq.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author: likelu
 * @Date: 2021/5/27 0027 10:39
 * @Description:
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @Resource
    private Producer producer;

    @GetMapping("/createBeforeOrder")
    public String createBeforeOrder() {

        String objId = IdUtil.objectId();
        try {
            /**
             * order_id
             * user_id
             * price
             * point
             * coupon_id
             * status
             * time
             */
            Db.use().execute("insert into `order` (order_id,user_id,price,point,coupon_id) values(?,?,?,?,?)",
                    objId, "A001","100","200", "C001");
            try {
                Thread.sleep(500);
                producer.msgToMq(objId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "true";
    }

}
